<template>
  <div class="main_box">
    <el-row>
      <el-col :span="12">
        <Crumbs></Crumbs>
      </el-col>
    </el-row>
    <el-row>
      <div class="search_wrap">
        <el-form :inline="true" :model="searchForm">
          <el-form-item>
            <el-input v-model="searchForm.customerCode" placeholder="代理编号"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="searchForm.customerNickName" placeholder="客户昵称"></el-input>
          </el-form-item>
          <el-form-item prop="date">
            <el-date-picker
              v-model="searchForm.date"
              :clearable="true"
              type="datetimerange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSearch">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-row>
    <el-row ref="tableRow">
      <el-table :data="tableList">
        <el-table-column type="index" label="序号" width="50"></el-table-column>
        <el-table-column prop="customerCode" label="客户编号"></el-table-column>
        <el-table-column prop="customerNickName" label="客户昵称"></el-table-column>
        <el-table-column prop="accountMoney" label="资金余额"></el-table-column>
        <el-table-column prop="statisticsMoney" label="冻结金额"></el-table-column>
        <el-table-column prop="cashMoney" label="可提现金额"></el-table-column>
        <el-table-column prop="createDate" label="创建时间"></el-table-column>
        <el-table-column label="操作" width="156" fixed="right">
          <template slot-scope="scope">
            <el-row>
              <el-button @click="handleClickDetail(scope.row)" size="mini">查看</el-button>
              <!--<el-button @click="handleClickReflect(scope.row)" size="mini">申请提现</el-button>-->
            </el-row>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.currentPage"
        :page-sizes="[5, 10, 20, 30]"
        :page-size="page.pageSize"
        layout="total, sizes, jumper, next, pager, prev"
        :total="page.pageTotal"
      ></el-pagination>
    </el-row>
  </div>
</template>
<script>
import Crumbs from '@/components/Crumbs';
import * as validators from '@/utils/validators';
import * as message from '@/constants/message';
import { FORMAT_DATE_YYYY_MM_DD } from '@/constants/constants';
import { mapGetters, mapActions } from 'vuex';

export default {
  data() {
    return {
      searchForm: {
        customerCode: '',
        customerNickName: '',
        date: [],
      },
      tableList: [],
      page: {
        pageNo: 1,
        pageSize: 20,
        pageTotal: 0,
        currentPage: 1,
      },

    };
  },
  components: {
    Crumbs,
  },
  mounted() {
    this.init();
    this.initDate();
  },
  methods: {
    init() {
      this.getTable();
      this.getTableHeight();
    },

    initDate() {
      let begin = new Date();
      begin.setHours(0);
      begin.setMinutes(0);
      begin.setSeconds(0);
      begin.setDate(1);
      let end = new Date();
      end.setHours(23);
      end.setMinutes(59);
      end.setSeconds(59);
      this.searchForm.date = [begin, end];
    },
    handleClickDetail(row) {
      this.$router.push({ path: '/money/CustomerAccountDetail', query: { id: row.customerAccountId } });
    },
    handleClickReflect(row) {
      this.$router.push({ path: '/money/CustomerAccountReflect', query: { id: row.customerId } });
    },
    handleCurrentChange(val) {
      this.page.pageNo = val;
      this.getTable();
    },
    handleSizeChange(size) {
      this.page.pageSize = size;
      this.getTable();
    },
    handleCurrentChange(val) {
      this.page.pageNo = val;
      this.getTable();
    },
    onSearch() {
      let searchData = {
        pageNo: this.page.pageNo,
        pageSize: this.page.pageSize,
        customerCode: this.searchForm.customerCode,
        customerNickName: this.searchForm.customerNickName,
      };

      if (this.searchForm.date && this.searchForm.date.length == 2) {
        (searchData.createDateBegin = this.$Utils.formatDate(this.searchForm.date[0], 'yyyy-MM-dd hh:mm:ss')),
          (searchData.createDateEnd = this.$Utils.formatDate(this.searchForm.date[1], 'yyyy-MM-dd hh:mm:ss'));
      }
      this.fetchData(searchData);
    },
    getTable() {
      let tableData = {
        pageNo: this.page.pageNo,
        pageSize: this.page.pageSize,
      };
      this.fetchData(tableData);
    },
    fetchData(data) {
      this.$emit('show-loading', true);
      this.$Get(this.$Config.api.customerAccountList, data)
        .then((res) => {
          this.tableList = res.data.list;
          this.page.pageTotal = res.data.total;
          this.page.currentPage = res.data.pageNum;
          this.$emit('show-loading', false);
        })
        .catch((error) => {
          console.error(error);
          this.$emit('show-loading', false);
        });
    },
  },
};
</script>
<style lang="scss" src="@/assets/css/views/content.scss"></style>
